package com.gin.kotlin.no_gay_alliance.model

import android.os.Parcelable
import com.gin.kotlin.no_gay_alliance.utils.TimeUtils
import com.gin.nga.response.checkin.CheckInBody
import com.gin.nga.response.checkin.CheckInStatus
import kotlinx.parcelize.Parcelize
import java.io.Serializable
import java.time.ZoneId
import java.time.ZonedDateTime

/**
 * 签到状态
 * @property message 一句骚话
 * @property userId 用户id
 * @property count 当前的连续签到天数(全局)
 * @property total 签到总天数
 * @property lastTime 上次签到时间
 * @property lastContinued 上次连续签到天数
 * @property lastContinuedDay 上次签到是第x天
 * @property lastDay 上次签到是第x天
 * @property week 星期?
 * @property nowDay 现在是第x天
 * @constructor
 */
@Parcelize
data class CheckInStatusModel(
    val message: String? = null,
    val userId: Long? = null,
    val count: Int? = null,
    val total: Int? = null,
    val lastTime: ZonedDateTime? = null,
    val lastContinued: Int? = null,
    val lastContinuedDay: Int? = null,
    val lastDay: Int? = null,
    val week: Int? = null,
    val nowDay: Int? = null,
) : Parcelable {
    constructor(status: CheckInStatus, message: String? = null) : this(
        userId = status.userId,
        count = status.count,
        total = status.total,
        lastTime = status.lastTime,
        lastContinued = status.lastContinued,
        lastContinuedDay = status.lastContinuedDay,
        lastDay = status.lastDay,
        week = status.week,
        nowDay = status.nowDay,
        message = message,
    )

    constructor(body: CheckInBody) : this(
        message = body.message?.get(0),
        status = body.status!!
    )

    fun toPairList(): MutableList<Pair<String, Serializable?>> {
        val list = mutableListOf<Pair<String, Serializable?>>()
        list.add(Pair("连续签到(天)", count))
        list.add(Pair("总签到(天)", total))
        list.add(Pair("上次签到时间", TimeUtils.SIMPLE_DATE_TIME_FORMATTER.format(lastTime?.withZoneSameInstant(ZoneId.systemDefault()))))
        list.add(Pair("上次连续签到天数", lastContinued))
        list.add(Pair("格林尼治时间-今天", nowDay))
        list.add(Pair("格林尼治时间-上次签到", lastDay))
        return list
    }
}
